#include "process.h"
#include <string.h>
#include <unistd.h>

#define NUM 101
#define STYLE '='
// version 2
void processbar(double total, double curent, int cnt){
	char bar[NUM] = "";
	memset(bar, '\0', sizeof bar);
	char spaces[] = "     ";
	char points[] = ".....";
	cnt %= 5;
	points[cnt + 1] = '\0';
	spaces[4 - cnt] = '\0';
	double rate = curent / total * 100;
	for(int i = 0;i < (int)rate;++i) bar[i] = STYLE;
	printf("[%-100s][%.1lf%%]%s%s\r", bar, rate, points, spaces);
	fflush(stdout);
}





// version 1
//void processbar(){
//	char bar[NUM];
//	memset(bar,'\0',sizeof bar);
//	bar[0] = '>';
//	const char lable[] = "|/-\\";
//	int len = strlen(lable);
//	int cnt = 0;
//	while(cnt < NUM){
//		printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt % len]);
//		fflush(stdout);
//		usleep(50000);	
//		bar[cnt ++] = STYLE;
//		if(cnt == NUM - 1) continue;
//		bar[cnt] = '>';
//	}
//	printf("\ncomplete!!!\n");
//}
